﻿using NFine.Application.ProductManage;
using NFine.Domain.Entity.ProductManage;
using System.Collections.Generic;
using System.Web.Mvc;
using NFine.Code;
using System;
using NFine.Domain._02_ViewModel;
using System.IO;
using NFine.Web.App_Start;
using WeiXin.SDK;
using WeiXin.SDK.Helpers;
using NFine.Domain._03_Entity.InformationCenter;
using System.Text;
using NFine.Application.Biz;
using NFine.Application.SystemManage;
using NFine.Domain._03_Entity.Weixin;
using NFine.Domain.Entity.SystemManage;
using NFine.Application._02_Weixin;
using NFine.Application.InformationCenter;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.Script.Serialization;
using NFine.Domain.Entity.Biz;
using System.Linq;
using WeiXin.SDK.Pay;
using NFine.Domain._03_Entity.Biz;

namespace NFine.Web.Areas.WeiXinAreas.Controllers
{
    public class MainController : Controller
    {
        private ProductApp _productApp = new ProductApp();
        private Application.InformationCenter.SysNewsApp _sysNewsApp = new Application.InformationCenter.SysNewsApp();
        private UserPropertyApp _userPropertyApp = new UserPropertyApp();
        private UserWithdrawalsApp _userWithdrawalsApp = new UserWithdrawalsApp();
        private UserBankApp _userBankApp = new UserBankApp();
        private IntegralDetailApp integralDetailApp = new IntegralDetailApp();
        private UserApp userApp = new UserApp();
        private UserDetailApp userDetailApp = new UserDetailApp();
        private UserOrderApp userOrderApp = new UserOrderApp();
        private HuangouIntegralApp hgApp = new HuangouIntegralApp();
        private ZhongZhuanPinJianApp zhzhApp = new ZhongZhuanPinJianApp();
        private SysMessagesApp messagesApp = new SysMessagesApp();
        private ItemsDetailApp itemsDetailApp = new ItemsDetailApp();
        private MemberBonusApp memberBonusApp = new MemberBonusApp();
        private AddressApp addressApp = new AddressApp();

        public Log FileLog
        {
            get { return LogFactory.GetLogger(this.GetType().ToString()); }
        }


        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //initUser();
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                #region 获取轮播图片
                var entity = messagesApp.getImages();
                List<string> ls = new List<string>();
                if (!string.IsNullOrEmpty(entity.F_Image1))
                    ls.Add(entity.F_Image1);
                if (!string.IsNullOrEmpty(entity.F_Image2))
                    ls.Add(entity.F_Image2);
                if (!string.IsNullOrEmpty(entity.F_Image3))
                    ls.Add(entity.F_Image3);
                if (!string.IsNullOrEmpty(entity.F_Image4))
                    ls.Add(entity.F_Image4);
                if (!string.IsNullOrEmpty(entity.F_Image5))
                    ls.Add(entity.F_Image5);
                ViewData["ListImage"] = ls;
                #endregion
                ViewData["gg"] = messagesApp.GetBasicSetting().F_Name;
                // 首页数据列表
                ViewData["IndexData"] = _productApp.GetList();//.GetIndexData();

                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Index");
            }
        }

        public ActionResult order(string pid)
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                var model = _productApp.GetForm(pid);

                return View(model);
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/order?pid=" + pid);
            }
        }

        private void initUser()
        {
            UserApp app = new UserApp();
            UserEntity userEntity = app.GetByOpenid("oUVDuvukfIl2BKIEcDElFtfLtIAg");//oUVDuvimNYPnzrDQhD212OGHCNC4   oUVDuvukfIl2BKIEcDElFtfLtIAg
            OperatorModel operatorModel = new OperatorModel();
            operatorModel.UserId = userEntity.F_Id;
            operatorModel.UserCode = userEntity.F_Account;
            operatorModel.UserName = userEntity.F_RealName;
            operatorModel.CompanyId = userEntity.F_OrganizeId;
            operatorModel.USERHEAD = userEntity.F_HeadIcon;
            operatorModel.DepartmentId = userEntity.F_DepartmentId;
            operatorModel.RoleId = userEntity.F_RoleId;
            operatorModel.LoginIPAddress = Net.Ip;
            operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress);
            operatorModel.LoginTime = DateTime.Now;
            operatorModel.LoginToken = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
            operatorModel.IsOrder = userEntity.F_DutyId != "1";
            operatorModel.phone = userEntity.F_MobilePhone;
            operatorModel.IsSystem = "admin".Equals(userEntity.F_Account);// userEntity.F_RoleId != Configs.GetValue("MemberRoleId");
            OperatorProvider.Provider.AddCurrent(operatorModel);
        }

        public ActionResult Ponser()
        {
            //UserInfoModel mod = new UserInfoModel();
            //mod.USERHEAD = "https://img.qlchat.com/qlLive/userHeadImg/741B03A8-15B7-4533-9BAB-2CACE92DFDF1-DVTJE3Q5ZO.jpg@132w_132h_1e_1c_2o";
            //mod.USERID = 24;
            //mod.USERNICKNAME = "傅强";
            //mod.USERROLE = "学员";
            //mod.TotalRevenue = 1000.ToString("F2");
            //mod.HasSettled = 800.ToString("F2");
            //mod.CanSettled = 200.ToString("F2");
            //Session["user"] = mod;

            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                var ud = userDetailApp.GetEntity(u.UserId);
                if (ud != null)
                {
                    var user = userApp.GetForm(u.UserId);
                    u.UserName = user.F_RealName;
                    u.phone = user.F_MobilePhone;
                    //if (u.IsOrder)
                    //{
                    //    var user = userApp.GetForm(u.UserId);
                    //    u.IsOrder = user.F_DutyId != "1";
                    //}
                    ViewData["level"] = userDetailApp.GetLevelText(ud);
                    //总收入 当月收入 已提现  账户余额

                    ViewData["all"] = userDetailApp.GetSumBounds(ud);
                    //ViewData["cur"] = ud.F_TeamConsume;
                    ViewData["cur"] = userDetailApp.GetSumBoundsForMonth(ud);

                    ViewData["bouns"] = userDetailApp.GetCurBounds(ud);

                    ViewData["tixian"] = userDetailApp.GetSumTiXian(ud);


                    //UserPropertyApp up = new UserPropertyApp();
                    //var upe = up.GetMemberProperty(u.UserId);
                    //ViewData["intger"] = upe.F_Property;

                    ViewData["kefutel"] = Configs.GetValue("Contact");

                    return View(u);
                }
                else
                    return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");

            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }

        public ActionResult Team()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                // var model = Session["user"] as UserInfoModel;
                return View();
            }

            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Team");
            }
        }
        public ContentResult getMoreTeams(int pagenum = 1, int count = 10)
        {
            Pagination page = new Pagination();
            page.page = pagenum;
            page.rows = count;
            page.sidx = "F_UserLevel";
            page.sord = "desc";
            var ls = userApp.GetList_WX(page);
            return Content(ls.ToJson());
        }

        public ActionResult Poster()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                var ud = userDetailApp.GetEntity(u.UserId);
                if (ud.F_UserLevel == 0)
                {
                    ViewData["canPic"] = false;
                    ViewData["info"] = "尚未成功正式代理商，不能生成海报";
                }
                else
                {
                    var parentId = u.UserId;
                    var folderPath = Server.MapPath("~/UploadFiles/qrcode/");
                    var picPath = folderPath + parentId + ".png";

                    var token = WeixinConfig.TokenHelper.GetToken();
                    var picUrl =
                        PromotionAPI.CreateParameterQrcode(token, ParameterQrcodeType.QR_SCENE, Convert.ToInt32(u.UserCode.Substring(2)), 7);

                    if (!Directory.Exists(folderPath))
                    {
                        Directory.CreateDirectory(folderPath);
                    }
                    FileStream fs = new FileStream(picPath, FileMode.Create);
                    Util.Download(picUrl, fs);
                    fs.Close();
                    fs.Dispose();
                    // 改为服务器相对地址
                    picPath = "/UploadFiles/qrcode/" + parentId + ".png";
                    ViewData["canPic"] = true;
                    ViewData["pic"] = picPath;
                    ViewData["date"] = DateTime.Now.ToString("yyyy年MM月dd日 HH:mm");
                }
                UserInfoModel uInfo = new UserInfoModel();
                uInfo.USERHEAD = u.USERHEAD;
                uInfo.USERNICKNAME = u.UserName;
                uInfo.USERNUMBER = u.UserCode;
                uInfo.WECHATACCOUNT = userDetailApp.GetLevelText(ud);
                return View(uInfo);
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Poster");
            }
        }


        /// <summary> 
        /// 商品详情
        /// </summary>
        /// <returns></returns>
        public ActionResult ProductInfo(string pid)
        {
            ProductEntity model = _productApp.GetForm(pid);

            ProductImageApp imageApp = new ProductImageApp();
            List<string> images = imageApp.GetListByParentId(pid);

            images.Insert(0, model.F_ImageUrl);

            ViewData["images"] = images;

            ViewData["kefutel"] = Configs.GetValue("Contact");

            return View(model);
        }

        public ActionResult CreateOrder(string pid,string addid="")
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                UserEntity user = userApp.GetForm(u.UserId);
                ViewData["UserName"] = user.F_RealName;
                ViewData["phone"] = user.F_MobilePhone;
                ViewData["addr"] = user.F_DepartmentId;
                ViewData["isinit"] = string.IsNullOrEmpty(user.F_MobilePhone) && string.IsNullOrEmpty(user.F_DepartmentId) ? "0" : "1";
                //获取中转中心
                //ViewData["TransferCenterList"] = userApp.GetAllTransferCenter();
                var pro = _productApp.GetForm(pid);
                List<ProductEntity> list = new List<ProductEntity>();
                list.Add(pro);
                ViewData["ProductData"] = list;// _productApp.GetList();
                var ud = userDetailApp.GetEntity(u.UserId);

                ViewData["curMoney"] = userDetailApp.GetCurBounds(ud);
                ViewData["pid"] = pid;


                var listItem = itemsDetailApp.GetList("dd3f3919-e568-476c-b0d6-7618fa6557eb");
                var taglevel = "";
                for (int i = 0; i < listItem.Count; i++)
                {
                    if (listItem[i].F_SimpleSpelling == pid)
                    {
                        taglevel = listItem[i].F_ItemCode;
                        break;
                    }
                }
                ///是不是代理商，如果代理商，是需要同时支付押金的
                ViewData["topman"] = taglevel == "3" ? "true" : "false";

                //Domain._03_Entity.Biz.UserPropertyEntity userPropertyEntity = _userPropertyApp.GetMemberProperty(u.UserId);

                //ViewData["Intger"] = userPropertyEntity.F_Property;

                if (!string.IsNullOrEmpty(addid)) {
                    var add = addressApp.GetForm(addid);
                    ViewData["F_Name"] = add.F_Name;
                    ViewData["F_Tele"] = add.F_Tele;
                    ViewData["F_Add"] = add.F_City.Replace(" ", "") + add.F_Add;
                    ViewData["F_ShopId"] = addid;
                }
                else
                {
                    var listadd = addressApp.GetList(u.UserId);
                    AddressEntity add = null;
                    if (listadd.Count > 0) {
                        foreach (var addent in listadd) {
                            if (addent.F_Default > 0) {
                                add = addent;
                                break;
                            }
                        }
                        if (add == null) {
                            add = listadd[0];
                        }
                        ViewData["F_Name"] = add.F_Name;
                        ViewData["F_Tele"] = add.F_Tele;
                        ViewData["F_Add"] = add.F_City.Replace(" ","") + add.F_Add;
                        ViewData["F_ShopId"] = add.F_Id;
                    }
                }

                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/CreateOrder?pid=" + pid);
            }
        }

        //private void cu()
        //{
        //    var userEntity = userApp.GetByAccount("FT000002")[0];
        //    OperatorModel operatorModel = new OperatorModel();
        //    operatorModel.UserId = userEntity.F_Id;
        //    operatorModel.UserCode = userEntity.F_Account;
        //    operatorModel.UserName = userEntity.F_RealName;
        //    operatorModel.CompanyId = userEntity.F_OrganizeId;
        //    operatorModel.USERHEAD = "../../Content/M/img/user.png";
        //    operatorModel.DepartmentId = userEntity.F_DepartmentId;
        //    operatorModel.RoleId = userEntity.F_RoleId;
        //    operatorModel.LoginIPAddress = Net.Ip;
        //    operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress);
        //    operatorModel.LoginTime = DateTime.Now;
        //    operatorModel.LoginToken = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
        //    operatorModel.IsOrder = userEntity.F_DutyId != "1";
        //    operatorModel.phone = userEntity.F_MobilePhone;
        //    operatorModel.IsSystem = "admin".Equals(userEntity.F_Account);// userEntity.F_RoleId != Configs.GetValue("MemberRoleId");
        //    OperatorProvider.Provider.AddCurrent(operatorModel);
        //}

        #region 提现操作相关
        /// <summary>
        /// 提现页面
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        public ActionResult TX(string cid = "")
        {
            var u = OperatorProvider.Provider.GetCurrent();
            var ud = userDetailApp.GetEntity(u.UserId);
            var curBounds = userDetailApp.GetCurBounds(ud);
            ViewData["haveWith"] = curBounds;

            var canWith = curBounds * 1000;

            Pagination page = new Pagination();
            page.page = 1;
            page.rows = 100;
            page.sidx = "F_WithdrawalsTime";
            page.sord = "desc";
            //提现手续费调整为1.5%----------2019.12.4
            var list = _userWithdrawalsApp.GetListForWithdrawals(page, 0, string.Empty, string.Empty, u.UserId);
            ViewData["list"] = list;
            foreach (var userwithdEntity in list)
            {
                canWith = canWith - (decimal)userwithdEntity.F_WithdrawalsMoney * 1015;
            }

            //var valstr = Math.Floor(canWith * 100 / 101).ToString("00");
            ViewData["canWith"] = Math.Round(canWith / 1015, 2); //valstr.Insert(valstr.Length - 2, valstr.Length==2?"0.":".") ;

            if (!string.IsNullOrEmpty(cid))
            {
                var li = _userBankApp.GetUserBankInfo(u.UserId);
                var card = li.Find(a => a.F_Id == cid);

                ViewData["card"] = card;
            }

            return View();
        }

        /// <summary>
        /// 账号列表页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult Account()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                var li = _userBankApp.GetUserBankInfo(u.UserId);
                return View(li);
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }

        /// <summary>
        /// 添加账户页面
        /// </summary>
        /// <returns></returns>
        public ActionResult addAccount()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                ViewData["uName"] = u.UserName;
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }
        /// <summary>
        /// 根据卡号获取银行名称
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult GetBank(string card)
        {
            var cardNumber = card.ToCharArray();
            int index;
            var name = BankInfo.GetBankName(cardNumber, out index); //获取银行卡的信息
            return Json(new { result = index, name = name }, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 保存账户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult submitAccount(Domain._03_Entity.Biz.UserBankEntity entity)
        {
            var u = OperatorProvider.Provider.GetCurrent();

            entity.F_CreateTime = DateTime.Now;
            entity.F_UserId = u.UserId;
            entity.F_AccountName = u.UserName;
            var result = _userBankApp.AddBank(entity);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 删除账户
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult delAccount(string cid)
        {
            var result = _userBankApp.DelBank(cid);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public ActionResult TXPost()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                //ViewData["uName"] = u.UserName;
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }

        /// <summary>
        /// 加载更多提现记录
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="pagenum"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ContentResult getMoreWith(int pagenum = 1, int count = 10)
        {
            var u = OperatorProvider.Provider.GetCurrent();
            Pagination page = new Pagination();
            page.page = pagenum;
            page.rows = count;
            page.sidx = "F_WithdrawalsTime";
            page.sord = "desc";
            var list = _userWithdrawalsApp.GetListForWithdrawals(page, -2, string.Empty, string.Empty, u.UserId);
            return Content(list.ToJson());
        }

        #endregion

        #region 收支明细
        /// <summary>
        /// 打开积分明细页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Payments()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }
        /// <summary>
        /// 获取更多积分明细
        /// </summary>
        /// <param name="pagenum"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ContentResult getMorePayments(int pagenum = 1, int count = 10)
        {
            var u = OperatorProvider.Provider.GetCurrent();
            Pagination page = new Pagination();
            page.page = pagenum;
            page.rows = count;
            page.sidx = "F_BonusTime";
            page.sord = "desc";
            //var ls = integralDetailApp.GetListForIntegral(page, u.UserId, -1, string.Empty, string.Empty);
            var ls = memberBonusApp.GetListForBonus(page, u.UserId, -1, string.Empty, string.Empty);
            return Content(ls.ToJson());
        }
        #endregion

        #region 完善微信登录信息
        /// <summary>
        /// 打开完善信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult UserInfo()
        {
            return View();
        }

        [HttpPost]
        public ActionResult submitUserInfo(Domain.Entity.SystemManage.UserEntity user, UserLogOnEntity userLogOnEntity)
        {
            if (Session["weinfo"] != null)
            {
                var weinfo = (WechatInfoEntity)Session["weinfo"];
                WechatInfoApp _wechatInfoApp = new WechatInfoApp();
                var wa = _wechatInfoApp.GetByOpenId(weinfo.F_openid);
                if (wa == null)
                {
                    _wechatInfoApp.InsertAsync(weinfo);
                }
                user.F_Gender = Request["F_Gender"].Equals("on");
                if (userApp.IsExistDepartmentId(user.F_DepartmentId, string.Empty))
                {
                    return new ContentResult
                    {
                        Content = "error:身份号信息重复！",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
                else if (userApp.InitWeixinUser(weinfo, user, userLogOnEntity))
                {
                    return new ContentResult
                    {
                        Content = "success:完善用户信息成功！",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
                else
                {
                    return new ContentResult
                    {
                        Content = "error:完善用户信息失败！",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
            }
            else
            {
                return new ContentResult
                {
                    Content = "error:等待超时，请重试！",
                    ContentType = "text/text",
                    ContentEncoding = UTF8Encoding.UTF8
                };
            }
        }

        /// <summary>
        /// 打开登录页面
        /// </summary>
        /// <returns></returns>
        public ActionResult login()
        {
            return View();
        }

        [HttpPost]
        [HandlerAjaxOnly]
        public ContentResult doLogin(string userName, string password)
        {
            if (Session["weinfo"] != null)
            {
                var weinfo = (WechatInfoEntity)Session["weinfo"];
                WechatInfoApp _wechatInfoApp = new WechatInfoApp();
                var wa = _wechatInfoApp.GetByOpenId(weinfo.F_openid);
                if (wa == null)
                {
                    _wechatInfoApp.InsertAsync(weinfo);
                }
                var userEntity = userApp.CheckLogin(userName, password);
                if (userEntity != null)
                {
                    userEntity.F_openid = weinfo.F_openid;
                    userEntity.F_HeadIcon = weinfo.F_headimgurl;
                    userApp.UpdateForm(userEntity);

                    OperatorModel operatorModel = new OperatorModel();
                    operatorModel.UserId = userEntity.F_Id;
                    operatorModel.UserCode = userEntity.F_Account;
                    operatorModel.UserName = userEntity.F_RealName;
                    operatorModel.CompanyId = userEntity.F_OrganizeId;
                    operatorModel.USERHEAD = userEntity.F_HeadIcon;
                    operatorModel.DepartmentId = userEntity.F_DepartmentId;
                    operatorModel.RoleId = userEntity.F_RoleId;
                    operatorModel.LoginIPAddress = Net.Ip;
                    operatorModel.LoginIPAddressName = Net.GetLocation(operatorModel.LoginIPAddress);
                    operatorModel.LoginTime = DateTime.Now;
                    operatorModel.LoginToken = DESEncrypt.Encrypt(Guid.NewGuid().ToString());
                    operatorModel.IsOrder = userEntity.F_DutyId != "1";
                    operatorModel.phone = userEntity.F_MobilePhone;
                    operatorModel.IsSystem = "admin".Equals(userEntity.F_Account);// userEntity.F_RoleId != Configs.GetValue("MemberRoleId");
                    OperatorProvider.Provider.AddCurrent(operatorModel);

                    return new ContentResult
                    {
                        Content = "success:用户绑定成功！",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
                else
                {
                    return new ContentResult
                    {
                        Content = "error:用户名或密码错误！",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
            }
            else
            {
                return new ContentResult
                {
                    Content = "error:操作超时，请重试！",
                    ContentType = "text/text",
                    ContentEncoding = UTF8Encoding.UTF8
                };
            }
        }
        #endregion

        #region 新闻列表
        public ActionResult NewsList()
        {
            return View();
        }

        public ContentResult GetNewForWeiXin(int offset)
        {
            var d = MaterialAPI.GetMediaList(WeixinConfig.TokenHelper.GetToken(), offset);
            List<View_TopIMG> lstopview = new List<View_TopIMG>();
            if (d.item_count > 0)
            {
                var items = d.item;
                for (int i = 0; i < d.item_count; i++)
                {
                    var item = items[i];
                    //var name = "uemOBvdiaNtmKrrMreuibB9FUKEv7YWmKtVcP0WF1GhakSmvjIPGtiav3uywuZibmaD76mKw3xCZN4Zicm5iaghehLEQ";// item.content.news_item[0].thumb_media_id;
                    //var path = Server.MapPath("~/upload/news/" + name + ".jpg");
                    //if (!System.IO.File.Exists(path))
                    //{
                    //    MaterialAPI.DownloadTempMedia(path, WeixinConfig.TokenHelper.GetToken(), name);
                    //}
                    View_TopIMG sysNew = new View_TopIMG();
                    sysNew.title = item.content.news_item[0].title;
                    sysNew.ID = item.content.news_item[0].url;
                    sysNew.content = item.content.news_item[0].digest;
                    sysNew.IMGsrc = item.content.news_item[0].thumb_url;// "upload/news/" + name + ".jpg";
                    lstopview.Add(sysNew);
                }
            }
            return Content(lstopview.ToJson());
        }

        /// <summary>
        /// 获取原来库中的新闻 已废弃
        /// </summary>
        /// <param name="pagenum"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ContentResult GetMoreNews(int pagenum = 1, int count = 10)
        {

            Pagination page = new Pagination();
            page.page = pagenum;
            page.rows = count;
            page.sidx = "F_CreatorTime";
            page.sord = "desc";
            List<SysNewsEntity> lstop = _sysNewsApp.GetList(page);
            List<View_TopIMG> lstopview = new List<View_TopIMG>();
            foreach (var a in lstop)
            {
                View_TopIMG topview = new View_TopIMG();
                int index = a.F_Content.IndexOf("<img ");
                if (index > -1)
                {
                    topview.ID = a.F_Id;
                    StringBuilder sb = new StringBuilder(a.F_Content.Substring(a.F_Content.IndexOf("src=\"") + 5));
                    sb = new StringBuilder(sb.ToString().Substring(0, sb.ToString().IndexOf('"')));
                    topview.IMGsrc = sb.ToString();
                    count++;
                }
                else
                {
                    topview.IMGsrc = WeixinConfig.Domain + "/Content/M/nomap.jpg";
                }
                topview.title = a.F_Title;
                topview.content = WebHelper.NoHtml(a.F_Content).Substring(0, WebHelper.NoHtml(a.F_Content).Length > 70 ? 70 : WebHelper.NoHtml(a.F_Content).Length);
                topview.clickcount = a.F_ClickCount;
                lstopview.Add(topview);
            }
            return Content(lstopview.ToJson());
        }


        public ActionResult News(string nid)
        {
            SysNewsEntity sys = _sysNewsApp.GetForm(nid);
            sys.F_ClickCount += 1;
            _sysNewsApp.SubmitForm(sys, nid);
            View_TopIMG topimg = new View_TopIMG();
            topimg.clickcount = sys.F_ClickCount;
            topimg.content = sys.F_Content;
            topimg.title = sys.F_Title;
            topimg.IMGsrc = ((DateTime)sys.F_CreatorTime).ToString("yyyy年MM月dd日 HH:mm");
            return View(topimg);
        }
        #endregion

        #region 积分换购
        public ActionResult HG()
        {
            var user = OperatorProvider.Provider.GetCurrent();
            if (!user.IsSys)
                ViewData["hgInt"] = zhzhApp.GetZhZhJF(user.UserId);
            else
                ViewData["hgInt"] = 0;

            ViewData["usertype"] = "huiyuan";
            if (user.RoleId == Configs.GetValue("TransferCenterRoleId"))
            {
                ViewData["usertype"] = "zhongzhuan";
            }
            else
            {
                ViewData["TransferCenterList"] = userApp.GetZhzhUser();
            }
            return View();
        }

        public ActionResult HGList()
        {
            return View();
        }

        public ActionResult getMoreHG(int pagenum = 1, int count = 10)
        {
            Pagination page = new Pagination();
            page.page = pagenum;
            page.rows = count;
            page.sidx = "F_CreateTime";
            page.sord = "desc";
            var list = zhzhApp.GetList(page, new DateTime(2018, 1, 1), DateTime.Now.AddDays(1), 0);
            return Content(list.ToJson());
        }
        #endregion

        #region 会员退出
        public ActionResult HYTC()
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                var user = userApp.GetForm(oper.UserId);
                user.F_HeadIcon = "";
                user.F_openid = "";
                userApp.UpdateForm(user);
                OperatorProvider.Provider.RemoveCurrent();
            }
            return View("UserInfo");
        }
        #endregion

        #region 授权证书
        public ActionResult shouquan()
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                var ud = userDetailApp.GetEntity(u.UserId);
                if (ud.F_UserLevel > 0)
                {
                    string imgpath = Request.MapPath("~/upload/shouquan/" + u.UserCode + ".jpg");
                    if (!System.IO.File.Exists(imgpath))
                    {
                        string userLevel = userDetailApp.GetLevelText(ud);
                        UserEntity ue = userApp.GetForm(ud.F_UserId);

                        string temppath = Request.MapPath("~/upload/shouquan/shouquan.jpg");
                        var imgBack = System.Drawing.Image.FromFile(temppath);
                        Graphics g = Graphics.FromImage(imgBack);
                        g.DrawString(userLevel, new Font(new FontFamily("楷体"), 48), new SolidBrush(Color.Black), 460, 550);
                        g.DrawString(ue.F_RealName, new Font(FontFamily.GenericSansSerif, 32), new SolidBrush(Color.Black), 300, 760);
                        g.DrawString(ue.F_MobilePhone, new Font(FontFamily.GenericSansSerif, 32), new SolidBrush(Color.Black), 700, 760);
                        g.DrawString(ud.F_UserName, new Font(FontFamily.GenericSansSerif, 32), new SolidBrush(Color.Black), 300, 880);
                        g.DrawString(u.UserCode, new Font(FontFamily.GenericSansSerif, 32), new SolidBrush(Color.Black), 700, 880);
                        if (ue.F_jihuoTime.HasValue)
                        {
                            var date = ue.F_jihuoTime.Value.ToString("yyyy-MM-dd") + " 至 " + ue.F_jihuoTime.Value.AddYears(3).AddDays(-1).ToString("yyyy-MM-dd");
                            g.DrawString(date, new Font(FontFamily.GenericSansSerif, 36), new SolidBrush(Color.Black), 340, 1000);
                        }
                        g.Dispose();
                        GC.Collect();
                        imgBack.Save(imgpath, ImageFormat.Png);
                        NFine.Code.Image.ImageClass.Compress(imgpath, imgpath);
                    }
                    ViewData["path"] = "../../upload/shouquan/" + u.UserCode + ".jpg";
                }
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Poster");
            }
        }
        #endregion

        #region 订单提交和支付
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitOrder(UserOrderEntity orderEntity, string jsonData, int isinit = 0, int payway = 0)
        {
            //if (Session["issubmit"] != null && Session["issubmit"].ToString() == "1")
            //{

            //    return Content(new AjaxResult { state = "", message = "" }.ToJson());
            //}
            //Session["issubmit"] = "1";
            jsonData = Server.UrlDecode(jsonData);
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            List<OrderItemEntity> list_OrderItems = serializer.Deserialize<List<OrderItemEntity>>(jsonData);

            var u = OperatorProvider.Provider.GetCurrent();

            var ud = userApp.GetForm(u.UserId);

            orderEntity.F_TotalMoney = list_OrderItems.Sum(a => a.F_TotalPrice);

            if (string.IsNullOrEmpty(orderEntity.F_ShopId))
            {
                return Content(new AjaxResult { state = ResultType.error.ToString(), message = "未设置收件地址!" }.ToJson());
            }
            var add = addressApp.GetForm(orderEntity.F_ShopId);
            if (add == null)
            {
                return Content(new AjaxResult { state = ResultType.error.ToString(), message = "无效的收件地址!" }.ToJson());
            }
            orderEntity.F_Consignee = add.F_Name;
            orderEntity.F_ContactNumber = add.F_Tele;
            orderEntity.F_Address = add.F_City.Replace(" ", "") + add.F_Add;
            //if (u.IsOrder)
            //{
            //    var user = userApp.GetForm(u.UserId);
            //    u.IsOrder = user.F_DutyId != "1";
            //}

            //if (u.IsOrder &&
            //orderEntity.F_TotalMoney < Convert.ToInt32(Configs.GetValue("PayMoney")))
            //{
            //    return Error("首次订单金额不足！");
            //}
            orderEntity.F_ProductPrice = orderEntity.F_TotalMoney;
            orderEntity.F_ProductNumber = 0;//表示此为首次订单

            orderEntity.F_Id = Common.GuId();
            orderEntity.F_OrderCode = DateTime.Now.ToString("yyyyMMddHHmmssfff");
            orderEntity.F_MemberId = OperatorProvider.Provider.GetCurrent().UserId;
            orderEntity.F_OrderTime = DateTime.Now;
            orderEntity.F_OrderStatus = 0;
            orderEntity.F_SendGoodsStatus = 0;
            foreach (var item in list_OrderItems)
            {
                item.F_Id = Common.GuId();
                item.F_OrderCode = orderEntity.F_OrderCode;
                item.F_ProductName = item.F_ProductName.Trim();
            }

            //订单操作 跟踪
            OrderActionEntity actionEntity = new OrderActionEntity();
            //actionEntity.F_Id = Common.GuId();
            //actionEntity.F_OrderCode = orderEntity.F_OrderCode;
            //actionEntity.F_UserId = orderEntity.F_MemberId;
            //actionEntity.F_Username = OperatorProvider.Provider.GetCurrent().UserName;
            //actionEntity.F_ActionCode = "创建订单";
            //actionEntity.F_ActionDate = orderEntity.F_OrderTime;
            //actionEntity.F_Remark = "创建订单";


            //判断支付方式，0为微信支付，1为余额支付
            if (payway == 1)
            {
                orderEntity.F_IsUseIntegral = true;

                var result = userOrderApp.SubmitOrder(orderEntity, list_OrderItems, actionEntity);
                if (isinit == 1)
                {
                    ud.F_RealName = orderEntity.F_Consignee;
                    ud.F_MobilePhone = orderEntity.F_ContactNumber;
                    ud.F_DepartmentId = orderEntity.F_Address;
                    userApp.UpdateForm(ud);
                }

                if (result > 0)
                {
                    result = userOrderApp.UpdateOrderStatus(orderEntity.F_Id);
                    if (result > 0)
                    {
                        FileLog.Debug("订单[" + orderEntity.F_OrderCode + "]余额支付成功，且完成分红！");
                        //如果处理结果是1000的话，删除原有的授权证书，在下次访问是会生成新的授权证书
                        if (result == 1000)
                        {
                            string imgpath = Request.MapPath("~/upload/shouquan/" + ud.F_Account + ".jpg");
                            if (System.IO.File.Exists(imgpath))
                                System.IO.File.Delete(imgpath);
                            FileLog.Debug("删除授权证书！");
                        }
                    }
                    else
                    {
                        FileLog.Debug("订单[" + orderEntity.F_OrderCode + "]未完成分红及状态更新！");
                    }
                    return Content(new AjaxResult { state = ResultType.success.ToString(), message = "订单提交成功!" }.ToJson());
                }
                else
                {
                    return Content(new AjaxResult { state = ResultType.error.ToString(), message = "订单提交失败!" }.ToJson());
                }
            }
            else
            {
                //微信支付
                int total_fee = (int)(orderEntity.F_TotalMoney * 100);

                var listItem = itemsDetailApp.GetList("dd3f3919-e568-476c-b0d6-7618fa6557eb");
                var taglevel = "";
                for (int i = 0; i < listItem.Count; i++)
                {
                    if (listItem[i].F_SimpleSpelling == list_OrderItems[0].F_ProductId)
                    {
                        taglevel = listItem[i].F_ItemCode;
                        break;
                    }
                }
                ///是不是代理商，如果代理商，是需要同时支付押金的
                if (taglevel == "3")
                {
                    total_fee += 2000 * 100;
                }

                //total_fee = 1;

                dynamic d = WxPayAPI.UnifiedOrder(WeixinConfig.AppID, WeixinConfig.mch_id, "WEB", orderEntity.F_OrderCode,
                    "睿步防滑-商品支付", list_OrderItems[0].F_ProductName, orderEntity.F_OrderCode, orderEntity.F_OrderCode, "CNY", total_fee, GetClientIp(),
                    DateTime.Now.ToString("yyyyMMddHHmmss"), DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"), "",
                    WeixinConfig.Domain + "/WeiXinAreas/Main/PayCallBack", "JSAPI", "", ud.F_openid,
                    WeixinConfig.PartnerKey);
                //LOGGER.Debug(d);.
                if (d.return_code != null && d.return_code.Value == "SUCCESS")
                {
                    var result = userOrderApp.SubmitOrder(orderEntity, list_OrderItems, actionEntity);
                    if (isinit == 1)
                    {
                        ud.F_RealName = orderEntity.F_Consignee;
                        ud.F_MobilePhone = orderEntity.F_ContactNumber;
                        ud.F_DepartmentId = orderEntity.F_Address;
                        userApp.UpdateForm(ud);
                    }

                    if (result > 0)
                    {
                        var stringADict = new Dictionary<string, string>();
                        stringADict.Add("appId", WeixinConfig.AppID);
                        stringADict.Add("nonceStr", Util.CreateNonce_str());
                        stringADict.Add("signType", "MD5");
                        stringADict.Add("package", "prepay_id=" + d.prepay_id.Value);
                        stringADict.Add("timeStamp", Util.CreateTimestamp().ToString());

                        /*string[] playurls = entity_live.PLAYURLS.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

                        var urls = new StringBuilder();
                        if (playurls.Length > 0)
                        {
                            foreach (string str in playurls)
                            {
                                urls.Append(",\"" + App_Start.WeixinConfig.yuedl + str + "\"");
                            }
                            //urls.Append(urls.Remove(0, 1).ToString());
                        }*/
                        string sign = WxPayAPI.Sign(stringADict, WeixinConfig.PartnerKey);
                        StringBuilder sb = new StringBuilder("{");
                        sb.Append("\"state\":\"SUCCESS\",\"wx\":");
                        sb.Append("{\"appId\":\"" + stringADict["appId"] + "\",");
                        sb.Append("\"timeStamp\":\"" + stringADict["timeStamp"] + "\",");
                        sb.Append("\"nonceStr\":\"" + stringADict["nonceStr"] + "\",");
                        sb.Append("\"package\":\"" + stringADict["package"] + "\",");
                        sb.Append("\"signType\":\"" + stringADict["signType"] + "\",");
                        sb.Append("\"paySign\":\"" + sign + "\"}");
                        //,sb.Append("\"playurls\":[" + urls.Remove(0, 1) + "]");
                        sb.Append("}");
                        return Content(new AjaxResult { state = ResultType.success.ToString(), message = sb.ToString() }.ToJson());
                    }
                    else
                        return Content(new AjaxResult { state = ResultType.error.ToString(), message = "订单提交失败!" }.ToJson());
                }
                else
                {
                    // Session["issubmit"] = null;
                    return Content(new AjaxResult { state = ResultType.error.ToString(), message = "微信支付调用失败!" }.ToJson());
                }
            }
        }

        public string getPostStr()
        {
            Int32 intLen = Convert.ToInt32(Request.InputStream.Length);
            byte[] b = new byte[intLen];
            Request.InputStream.Read(b, 0, intLen);
            return System.Text.Encoding.UTF8.GetString(b);
        }

        /// <summary>
        /// 微信支付回调，修改支付状态
        /// </summary>
        public void PayCallBack()
        {
            string resultFromWx = getPostStr();
            dynamic res = new DynamicXml(resultFromWx);
            FileLog.Debug("订单[" + res.attach.Value + "]支付回调成功！" + resultFromWx);
            UserOrderEntity orderEntity = userOrderApp.GetFormForOrderCode(res.attach.Value);
            if (orderEntity != null && orderEntity.F_OrderStatus == 0)
            {
                FileLog.Debug("订单[" + res.attach.Value + "]已经找到！");
                var result = userOrderApp.UpdateOrderStatus(orderEntity.F_Id);
                if (result > 0)
                {
                    FileLog.Debug("订单[" + orderEntity.F_OrderCode + "]支付回调成功，且完成分红！");
                    //如果处理结果是1000的话，删除原有的授权证书，在下次访问是会生成新的授权证书
                    if (result == 1000)
                    {
                        var u1 = userApp.GetForm(orderEntity.F_MemberId);
                        string imgpath = Request.MapPath("~/upload/shouquan/" + u1.F_Account + ".jpg");
                        if (System.IO.File.Exists(imgpath))
                            System.IO.File.Delete(imgpath);
                        FileLog.Debug("删除授权证书！");
                    }
                }
                else
                {
                    FileLog.Debug("订单[" + orderEntity.F_OrderCode + "]未完成分红及状态更新！");
                }
                //Task.Run(() =>
                //{
                //    ///支付成功后，向平台方发送信息
                //    string strcontent = "【梦境大理】有新订单，单号：" + res.attach.Value + "，请及时处理。";
                //    string url = "http://120.55.248.18/smsSend.do?username=mengyouzhidi&password=b71fd667d8bf3b32e1370ae67c13002a&mobile=" + WeixinConfig.phone + "&content=" + HttpUtility.UrlEncode(strcontent, System.Text.Encoding.UTF8);
                //    WebRequest req = WebRequest.Create(url);
                //    req.GetResponse();

                //});
            }
        }

        /// <summary>
        /// 获取客户端Ip
        /// </summary>
        /// <returns></returns>
        private String GetClientIp()
        {
            String clientIP = "";
            if (System.Web.HttpContext.Current != null)
            {
                clientIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
                if (string.IsNullOrEmpty(clientIP) || (clientIP.ToLower() == "unknown"))
                {
                    clientIP = System.Web.HttpContext.Current.Request.ServerVariables["HTTP_X_REAL_IP"];
                    if (string.IsNullOrEmpty(clientIP))
                    {
                        clientIP = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
                    }
                }
                else
                {
                    clientIP = clientIP.Split(',')[0];
                }
            }
            return clientIP;
        }
        #endregion

        /// <summary>
        /// 打开完善信息页面
        /// </summary>
        /// <returns></returns>
        public ActionResult SetUserInfo()
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                ViewData["accout"] = oper.UserCode;
                UserEntity u = userApp.GetForm(oper.UserId);
                ViewData["F_RealName"] = u.F_RealName;
                ViewData["F_MobilePhone"] = u.F_MobilePhone;
                ViewData["F_DepartmentId"] = u.F_DepartmentId;
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Poster");
            }
        }

        [HttpPost]
        public ActionResult submitSetUserInfo(Domain.Entity.SystemManage.UserEntity user)
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                UserEntity ue = userApp.GetForm(oper.UserId);
                ue.F_RealName = user.F_RealName;
                ue.F_MobilePhone = user.F_MobilePhone;
                ue.F_DepartmentId = user.F_DepartmentId;
                userApp.UpdateForm(ue);
                return new ContentResult
                {
                    Content = "success:基础信息设置完成！",
                    ContentType = "text/text",
                    ContentEncoding = UTF8Encoding.UTF8
                };
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Poster");
            }
        }
        /// <summary>
        /// 我的订单
        /// </summary>
        /// <returns></returns>
        public ActionResult OrderList(int type = 1)
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                ViewData["nowType"] = type;
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Poster");
            }
        }

        /// <summary>
        /// 根据订单状态、用户类型、用户ID查询订单信息列表 分页
        /// </summary>
        /// <param name="userType">用户类型（0:会员 1:业务经理 2:供货商 3:终端 4:股东）</param>
        /// <param name="userId">用户ID</param>
        /// <param name="type">订单状态（1:全部订单 2:订单处理中 3:发货处理中 4:已完成）</param>
        /// <param name="pagenum"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public ContentResult getMoreOrders(int type = -1, int pagenum = 1, int count = 10)
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                //MemberXEntity memberXEntity = Session["NormalMember"] as MemberXEntity;

                //TODO model 暂时写死
                //memberXEntity = personalClientApp.GetPersonalInfoById("456");

                Pagination page = new Pagination();
                page.page = pagenum;
                page.rows = count;
                page.sidx = "F_OrderTime";
                page.sord = "desc";
                var ls = userOrderApp.GetListForOrder(page, type, string.Empty, string.Empty, string.Empty, string.Empty, oper.UserId);
                return Content(ls.ToJson());
            }
            else
            {
                return new ContentResult
                {
                    Content = "error:请求超时，需要重新授权！",
                    ContentType = "text/text",
                    ContentEncoding = UTF8Encoding.UTF8
                };
            }
        }
        /// <summary>
        /// 用户的确认收货，订单完成
        /// </summary>
        /// <param name="ordercode"></param>
        /// <returns></returns>
        public ContentResult submitSH(string ordercode)
        {
            var oper = OperatorProvider.Provider.GetCurrent();
            if (oper != null)
            {
                if (userOrderApp.ZFOrder(ordercode, 3) > 0)
                {
                    return new ContentResult
                    {
                        Content = "success:OK",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
                else
                {
                    return new ContentResult
                    {
                        Content = "error:更新订单状态失败。",
                        ContentType = "text/text",
                        ContentEncoding = UTF8Encoding.UTF8
                    };
                }
            }
            else
            {
                return new ContentResult
                {
                    Content = "error:请求超时，需要重新授权！",
                    ContentType = "text/text",
                    ContentEncoding = UTF8Encoding.UTF8
                };
            }
        }
        #region 地址管理
        /// <summary>
        /// 账号列表页显示
        /// </summary>
        /// <returns></returns>
        public ActionResult Address(string pid="")
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {                
                ViewData["pid"] = pid;
                var li = addressApp.GetList(u.UserId);
                return View(li);
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }

        /// <summary>
        /// 添加账户页面
        /// </summary>
        /// <returns></returns>
        public ActionResult addAddress(string add_Id,string pid="")
        {
            var u = OperatorProvider.Provider.GetCurrent();
            if (u != null)
            {
                //ViewData["uName"] = u.UserName;
                if (!string.IsNullOrEmpty(add_Id)) {
                    var add = addressApp.GetForm(add_Id);
                    ViewData["F_City"] = add.F_City;
                    ViewData["F_Add"] = add.F_Add;
                    ViewData["F_Name"] = add.F_Name;
                    ViewData["F_Tele"] = add.F_Tele;
                    ViewData["F_UserId"] = add.F_UserId;
                    ViewData["F_Id"] = add_Id;
                }
                ViewData["pid"] = pid;
                return View();
            }
            else
            {
                return Redirect("/Weixin/NeedToUser?uri=/WeiXinAreas/Main/Ponser");
            }
        }
        /// <summary>
        /// 保存账户
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult submitAddress(Domain._03_Entity.Biz.AddressEntity entity)
        {
            var u = OperatorProvider.Provider.GetCurrent();
            
            entity.F_UserId = u.UserId;
            var result = addressApp.SubmitForm(entity);
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        /// <summary>
        /// 删除账户
        /// </summary>
        /// <param name="cid"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult delAddress(string add_id)
        {
            var result = addressApp.DeleteForm(add_id);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}